package com.baby.movie.app.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.baby.movie.R;
import com.baby.movie.util.ImageUtil;
import com.baby.movie.widget.MProgress;
import com.common.util.AndroidUtil;

public abstract class BaseFragment extends Fragment {
	
	protected Context mContext;
	
	protected LayoutInflater mInflater;
	
	protected MProgress mVProgress;

	protected abstract int getContentViewRes();
	
	protected abstract void findViews(View contentView);
	
	protected abstract void initialize();
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mInflater = inflater;
		View rootView = mInflater.inflate(R.layout.refresh_container, container, false);
		FrameLayout parent = (FrameLayout) rootView.findViewById(R.id.viewContent);
		mVProgress = (MProgress) rootView.findViewById(R.id.mProgress);
		
		View contentView = mInflater.inflate(getContentViewRes(), null);
		findViews(contentView);
		
		parent.addView(contentView);
		return rootView;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		mContext = getActivity();
		initialize();
	}
	
	protected static void loadThumb(String url, ImageView imageView) {
		ImageUtil.loadThumb(url, imageView);
	}
	
	protected static void loadImage(String url, ImageView imageView) {
		if (AndroidUtil.isEmpty(url)) {
			imageView.setImageResource(R.drawable.logo);
		} else {
			ImageUtil.loadImage(url, imageView);
		}
	}
	
	public void toast(String msg) {
    	AndroidUtil.toastS(mContext, msg);
	}
	
    public void toast(int msgRes) {
		AndroidUtil.toastS(mContext, msgRes);
	}
    
    protected void showProgress() {
		mVProgress.showProgress();
	}
    
    protected void hideProgress() {
		mVProgress.hide();
	}
    
    protected void setMessage(String msg) {
		mVProgress.setMessage(msg);
	}
}
